home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
10,000 Great Games
/
10,000 Great Games.iso
/
Product
/
66
/
data1.cab
/
Source_Files
/
Src
/
Dsound.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-16
|
1KB
|
80 lines
#include "stdafx.h"
LPDIRECTSOUND DS = 0;
LPDIRECTSOUNDBUFFER soundcard = 0;
int no_sound = FALSE;
void init_directsound()
{
// Get DirectSound object
if (no_sound || FAILED(DirectSoundCreate(0, &DS, 0)))
{
no_sound = TRUE;
return;
}
}
void init_directsound_primarybuffer()
{
if (no_sound)
return;
// Set cooperative level
if(FAILED(DS->SetCooperativeLevel(mainwindowhandle, DSSCL_NORMAL)))
error("Unable to set cooperative level for sound card");
// Create primary buffer
DSBUFFERDESC dsbd;
ZeroMemory(&dsbd, sizeof(dsbd));
dsbd.dwSize = sizeof(dsbd);
dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
if (FAILED(DS->CreateSoundBuffer(&dsbd, &soundcard, 0)))
error("Unable to create primary sound buffer");
// Start playing silence
soundcard->Play(0, 0, DSBPLAY_LOOPING);
}
void deinit_directsound()
{
safe_release(&soundcard);
safe_release(&DS);
}
void play_sound(cWAV *snd, int volume)
{
if (no_sound)
return;
snd->dsb->SetCurrentPosition(0);
snd->dsb->SetVolume(volume);
snd->dsb->Play(0,0,0);
}
void ambient_sounds()
{
static cTimer wait;
if (!wait && !no_sound)
{
switch(rnd(2))
{
case 0:
play_sound(cWAV::get("ALARM"));
break;
case 1:
play_sound(cWAV::get("CREAK"));
break;
}
wait = rnd(40 * sec);
}
}